package cate.game.activity.zonelimit.po;

import cate.common.table.activity.zonelimit.row.ZoneLimitBoxRow;
import cate.common.table.activity.zonelimit.row.ZoneLimitItemRow;
import cate.common.util.GameResult;
import cate.game.activity.base.core.ActivityGlobalData;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcResult;

import java.util.HashMap;
import java.util.Map;

@NoteClass(value = "全民礼包",detail = "全服数据")
public class ZoneLimit extends ActivityGlobalData {

	@NoteField(value = "本期购买次数",detail = "Map<档位,次数>")
	public Map<Integer,Integer> buyMap;

//	@NoteField(value = "日常购买次数",detail = "Map<档位,次数>")
//	public Map<Integer,Integer> dailyBuy;

	public void initialize() {
		super.initialize();
		if (buyMap == null) {
			buyMap = new HashMap<>();
		}
//		if (dailyBuy == null) {
//			dailyBuy = new HashMap<>();
//		}
	}


	@Override
	public void clear() {
		buyMap.clear();
//		dailyBuy.clear();
	}

	public GameResult<Void> allowPay(ZoneLimitItemRow itemRow) {
		GameResult<Void> r = new GameResult<>();
		if (buyMap.getOrDefault(itemRow.priceNo, 0) >= itemRow.zoneLimit) {
			return r.fail("全服已售罄");
		}
		return r.success();
	}

	public void onPaySuccess(ZoneLimitItemRow itemRow) {
//		int buy = dailyBuy.getOrDefault(itemRow.priceNo, 0);
//		if (itemRow.day == getCurrentDay()) {
//			dailyBuy.put(itemRow.priceNo, buy + 1);
//		}
		buyMap.put(itemRow.priceNo, buyMap.getOrDefault(itemRow.priceNo, 0) + 1);
	}

	public GameResult allowGetBox(ZoneLimitBoxRow boxRow) {
		GameResult r = new GameResult();
//		if (boxRow.day != getCurrentDay()) {
//			return r.fail("奖励已过期");
//		}
		if (buyMap.getOrDefault(boxRow.priceNo, 0) < boxRow.num) {
			return r.fail("购买次数不足");
		}
		return r.success();
	}

	public void onDaySpan() {
//		dailyBuy.clear();
	}
}
